<?php

	/*
	 * Add functionality for create project, alter project
	 * 
	 */

	class Project {
	
		private $table = "Projekt";
		private $db;
	
	    function __construct() {
	    	
	    	include_once("../classes/database.class.php");
			$this->db = new Database("../database/timemanagement.db");
	    }
	    
	    function createProject($name, $date, $budget) {
	    	$data = array(
	    			'Name' => $name,
	    			'Deadline' => $date,
	    			'Budget' => $budget);
			$table = $this->table;
	    	$database = $this->db;
	    	//$database -> connect();
	    	$this->db->insert($table, $data);
	    	
	    	return $data;
	    	
	    	
	    }
	    
	    function alterProject($data, $id) {
	    	
	    	$where = array(
	    		"pk_nr" => $id
	    	);
	    	
	    	$this->db->update($this->table, $data, $where);
	    }
	    
	    
	 	function getProjectDetailView($id) {

	 		$where = array(
	 			'pk_nr' => $id
	 		);
	 		
	 		$columns = array();
			$columns[] = "pk_nr";
			$columns[] = "name";
			$columns[] = "deadline";
			$columns[] = "budget";
		
			return $this->db->select($this->table, $columns, $where);
	 
	 	}
	    
	    // for development
	    function getEverything() {
	    	
	    	return $this->db->select($this->table, "*");
	    }
	    
	    function checkDate($date,$format,$sep)
	    {
	    
	    	$p1    = strpos($format, 'd');
	    	$p2    = strpos($format, 'm');
	    	$p3    = strpos($format, 'Y');
	    
	    	$check    = explode($sep,$date);
	    
	    	return checkDate($check[$p2],$check[$p1],$check[$p3]);
	    
	    }
	}
?>